<?php

class Demand_pdf extends FPDF
{
    private $a_DS;
    private $a_filial;
    private $a_manager;
    private $a_orderer;
    
    public function SetDS($p_DS){
		$this->a_DS = $p_DS;
    }
    
    public function SetFilial($p_filial){
	$this->a_filial = $p_filial;
    }

    public function SetManager($p_manager){
	$this->a_manager = $p_manager;
    }

    public function SetOrderer($p_orderer){
    	$this->a_orderer = $p_orderer;
    }
    
    public function GetDemand(){
		$this->AddPage();
		$this->AddFont('ArialMT','','arial.php');
		$this->AddFont('ArialBD','','arialbd.php');
		$this->DemandTitle();
		$this->DemandClients();
		$this->DemandTour();
		$this->DemandFooter();
		$this->Output();
    }    
    
    private function DemandTitle(){
        $this->SetFont('ArialBD','',8);	
        $this->Cell(80);
        //Title
        $this->SetXY(5,5);
        $str = "Додаток №1 до Договору на туристичне обслуговування  №{$this->a_DS[0]->agreement}  вiд {$this->a_DS[0]->date_doc}р.";
        $this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str));
        $this->Ln(8);
        $this->SetFont('ArialMT','',10);	
        $str = "ТОВ \"МЕРЕЖА ТУРИСТИЧНИХ АГЕНЦІЙ ПЕРСОНАЛЬНОГО ВІДПОЧИНКУ\"";
        $this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'C');
		//Line break
        $this->Ln(1);
		$str =	"Україна, м.{$this->a_filial->city_name},\nвул.{$this->a_filial->adress},  т/ф {$this->a_filial->phones}, e-mail: {$this->a_filial->email}";
        $this->MultiCell(0,4,iconv('UTF-8', 'Windows-1251', $str), 1, 'C');
        $this->Ln(2);
    }
    
    public function DemandClients(){
    	$this->SetFont('ArialMT','',8);	
        $str = "ЗАЯВКА  на бронювання туристичних послуг";
        $this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'C');
        $str = "№";
    	$this->Cell(20,5,iconv('UTF-8', 'Windows-1251', $str), 1, 0, 'C');
        $str = "Призвіще (РУС / ЛАТ)";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'TBR', 0, 'C');
        $str = "Ім'я (РУС / ЛАТ)";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'TBR', 0, 'C');
        $str = "№ ПАСПОРТА,термін дії ";
    	$this->Cell(40,5,iconv('UTF-8', 'Windows-1251', $str), 'TBR', 0, 'C');
        $str = "ДАТА НАРОДЖЕННЯ";
    	$this->Cell(40,5,iconv('UTF-8', 'Windows-1251', $str), 'TBR', 0, 'C');
    	$this->Ln();
    	//
    	$i = 1;
    	foreach($this->a_DS as $client){
	        $str = $i;
    		$this->Cell(20,5,iconv('UTF-8', 'Windows-1251', $str), 'LR', 0, 'C');
       		$str = $client->l_name;
    		$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'R', 0, 'C');
        	$str = $client->f_name;
    		$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'R', 0, 'C');
        	$str = $client->f_pass_seria.' '.$client->f_pass_num;
    		$this->Cell(40,5,iconv('UTF-8', 'Windows-1251', $str), 'R', 0, 'C');
        	$str = $client->birthday;
    		$this->Cell(40,5,iconv('UTF-8', 'Windows-1251', $str), 'R', 0, 'C');
    		$this->Ln();
	        $str = '';
    		$this->Cell(20,5,iconv('UTF-8', 'Windows-1251', $str), 'LRB', 0, 'C');
       		$str = $client->l_name_lat;
    		$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'C');
        	$str = $client->f_name_lat;
    		$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'C');
        	$str = $client->f_pass_period;
    		$this->Cell(40,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'C');
        	$str = '';
    		$this->Cell(40,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'C');
    		$this->Ln();
    		$i++;
    	}
    	$this->Ln(2);
    }
    
    public function DemandTour(){
    	$this->SetFont('ArialMT','',8);	
        $str = "ДЕТАЛІ  ТУРА";
        $this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'C');
        
        $str = "КРАЇНА / КУРОРТ / МіСТО";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 1, 0, 'L');
        $str = $this->a_DS[0]->country_name.'/'.$this->a_DS[0]->curourt_name.'/'.$this->a_DS[0]->city_name;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'TBR', 0, 'L');
    	$this->Ln();

        $str = "ДАТА ТУРУ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LRB', 0, 'L');
        $str = "c: {$this->a_DS[0]->date_from}       по: {$this->a_DS[0]->date_to}";
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();
    	
        $str = "ТРИВАЛІСТЬ ТУРУ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = $this->a_DS[0]->tour_period.' днiв '.($this->a_DS[0]->tour_period-1).' ночей ';
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();
    	
        $str = "НАЗВА ТА КАТЕГОРІЯ ГОТЕЛЮ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = $this->a_DS[0]->hotel_name.' '.$this->a_DS[0]->hotelcat_name;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();

        $str = "ТИП НОМЕРУ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = $this->a_DS[0]->room_name;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();
    	
        $str = "ХАРЧУВАННЯ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = $this->a_DS[0]->food_name;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();

        $str = "ТРАНСФЕР";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = $this->a_DS[0]->transfer;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();

        $str = "ЕКСКУРСІЇ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = $this->a_DS[0]->excursions;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();
    	
        $str = "СТРАХОВА КОМПАНІЯ";
    	$this->Cell(45,5,iconv('UTF-8', 'Windows-1251', $str), 'LBR', 0, 'L');
        $str = '';//$this->a_DS[0]->cif_name;
    	$this->Cell(145,5,iconv('UTF-8', 'Windows-1251', $str), 'BR', 0, 'L');
    	$this->Ln();
    	
    }
    
    public function DemandFooter(){
        $str = "Дод.інформація: {$this->a_DS[0]->descr}";
    	$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'L');
        $str = "Загальна вартість туристичних послуг (цифрами та прописом): {$this->a_DS[0]->summ} {$this->a_DS[0]->right_word}({$this->a_DS[0]->summ_text})";
    	$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'L');
    	if($this->a_DS[0]->summ > $this->a_DS[0]->summ_pay) {
        	$str = "ПЕРЕДПЛАТА: {$this->a_DS[0]->summ_pay} {$this->a_DS[0]->right_word}";
    		$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'L');
    	}	
    	else{
        	$str = "ПОВНА ОПЛАТА:{$this->a_DS[0]->summ_pay} {$this->a_DS[0]->right_word}";
    		$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'L');
    	}
        $str = "КОНТАКТИ (тел. дом.; моб.): {$this->a_orderer->phones}, {$this->a_orderer->email}";
    	$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 1, 'L');
    	$this->Ln();
    	$str = "ВІДПОВІДАЛЬНИЙ МЕНЕДЖЕР";
    	$this->Cell(120,5,iconv('UTF-8', 'Windows-1251', $str), 0, 0, 'L');
    	$str = "КЛIЄНТ";
    	$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 0, 'L');
    	$this->Ln();
    	$str = "______________/{$this->a_manager}/";
    	$this->Cell(120,5,iconv('UTF-8', 'Windows-1251', $str), 0, 0, 'L');
    	$str = "______________/                                         /";
    	$this->Cell(0,5,iconv('UTF-8', 'Windows-1251', $str), 0, 0, 'L');
    	$this->Ln();
    	$str = "МП";
    	$this->Cell(120,20,iconv('UTF-8', 'Windows-1251', $str), 0, 0, 'L');
    	$str = date('d.m.Y');
    	$this->Cell(0,20,iconv('UTF-8', 'Windows-1251', $str), 0, 0, 'R');
    	$this->Ln();
    	
    }
    
}
?>